package logic

import (
	"context"
	"usershop/user_srv/internal/svc"
	"usershop/user_srv/model/redis"
	"usershop/user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type CacheSmsCodeLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCacheSmsCodeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CacheSmsCodeLogic {
	return &CacheSmsCodeLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CacheSmsCodeLogic) CacheSmsCode(in *user.ResSmsCodeRequest) (*user.CacheSmsCodeResMsg, error) {
	//todo: 发送短信  缓存短信验证码

	err := redis.ResisterSmsCode(in.Tel, in.Code, in.Source)
	if err != nil {
		logx.Error("短信缓存写入失败", err)
		return nil, err
	}

	return &user.CacheSmsCodeResMsg{}, nil
}
